<?php
/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2019/2/20
 * Time: 11:32
 */

namespace app\services;


use app\api\model\OrderModel;
use app\api\model\UserModel;

class MessageServices
{
    /**
     * @desc  向商户或者用户推送消息
     * @param $to_group   接收分组  商户/用户
     * @param $to_uid     接收人送人id  可以多个
     * @param $messageid  消息id
     * @return mixed      返回发送结果 成功/失败
     */
    public static function pushmessage($uid,$tid,$yid)
    {
      $user=UserModel::where('uid',$uid)->find();
        $host=$_SERVER['SERVER_ADDR'];
        $push_api_url = "http://".$host.":2121/";
        $post_data = array(
            "type" => "publish",
            "content" => $yid,
            "id"=>$tid,//订单id
            "to_group"=>'f',
            "to" => $user['login_rand'],
        );
        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_URL, $push_api_url );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
        curl_setopt ($ch, CURLOPT_HTTPHEADER, array("Expect:"));
        $return = curl_exec ( $ch );
        curl_close ( $ch );
        return $return;
    }
}